<template>
  <div v-loading="loading.status" class="body">
    <el-form ref="refForm" v-loading="loading.form" class="form" :model="form" size="mini">
      <el-row style="padding: 30px">
        <el-col :span="24" :xs="24" :md="12" :lg="12">
          <el-form-item v-if="jsAuthJudgment('manage')" label="商务人员" prop="business_uid"
            :label-width="fromViewCofing.label_width">
            <el-select v-model="form.business_uid" placeholder="请选择" :filterable="true" class="inp" size="mini"
              @change="changeSelectBusinessuid">
              <el-option v-for="item in business_list" :key="item.id" :label="item.nickname" :value="item.id">
                <span style="float: left">{{ item.nickname }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{
                  item.group_name
                }}</span>
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="机构" prop="o_id" :label-width="fromViewCofing.label_width">
            <el-select v-model="form.o_id" placeholder="请选择" :filterable="true" size="mini" class="inp">
              <el-option v-for="item in organization_select" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>

          <el-form-item :rules="[{ required: true, message: '产品名字不能为空' }]" label="产品名字" prop="name"
            :label-width="fromViewCofing.label_width">
            <el-input v-model="form.name" class="inp" size="mini" />
          </el-form-item>

          <el-form-item :rules="[{ required: true, message: '计划名字不能为空' }]" label="计划名字" prop="plan_name"
            :label-width="fromViewCofing.label_width">
            <el-input v-model="form.plan_name" class="inp" size="mini" />
          </el-form-item>

          <el-form-item :rules="[{ required: true, message: '合作价格不能为空' }]" label="合作价格" prop="cooperative_price"
            :label-width="fromViewCofing.label_width">
            <el-input v-model="form.cooperative_price" class="inp" size="mini" />
          </el-form-item>

          <!--   代理分成只能管理员看    -->
          <el-form-item :rules="[{ required: true, message: '代理分成不能为空' }]" label="代理分成" prop="agency_price"
            :label-width="fromViewCofing.label_width" v-if ="isManage">
            <el-input v-model="form.agency_price" class="inp" size="mini" />
          </el-form-item>

          <el-form-item label="真实价格" :label-width="fromViewCofing.label_width" v-if ="isManage">
            <el-input v-model="form.real_price" disabled class="inp" size="mini" />
          </el-form-item>

          <!--    权重只有管理员才能操作,其他只能看    -->
          <el-form-item label="权重" :label-width="fromViewCofing.label_width" v-if ="isManage">
            <el-input v-model="form.weight" class="inp" size="mini" />
          </el-form-item>

          <el-form-item label="产品分类" :label-width="fromViewCofing.label_width">
            <el-select v-model="form.category" placeholder="请选择">
              <el-option label="机构" value="organization">
              </el-option>
              <el-option label="机构API" value="organization_api">
              </el-option>
              <el-option label="下游全流程 - 分润" value="ds_flow_cps">
              </el-option>
              <el-option label="下游全流程 - 固价" value="ds_flow_fixed">
              </el-option>
              <el-option label="跳转第三方链接" value="ext_link">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item v-if="form.category == 'ext_link'" label="第三方链接" :label-width="fromViewCofing.label_width">
            <el-input v-model="form.ext_link" class="inp" size="mini" />
          </el-form-item>

          <el-form-item v-if="jsAuthJudgment('manage')" label="渠道条件类型" :label-width="fromViewCofing.label_width">
            <el-radio-group v-model="form.is_exclusive">
              <el-radio :label="1">独享</el-radio>
              <el-radio :label="0">共享</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="进件状态" :label-width="fromViewCofing.label_width">
            <el-switch v-model="form.entry_status" :active-value="1" :inactive-value="0" size="mini" />
          </el-form-item>

          <el-form-item label="助贷类型" :label-width="fromViewCofing.label_width">
            <el-radio-group v-model="form.loan_type" size="mini">
              <el-radio label="nationwide">全国</el-radio>
              <el-radio label="region">地区</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item v-show="form.loan_type == 'region'" label="地区" :label-width="fromViewCofing.label_width">
            <el-cascader v-model="form.regions" size="mini" placeholder="请选择地区" class="inp"
              :props="{ multiple: true, checkStrictly: true }" :options="city" clearable filterable />
          </el-form-item>

          <el-form-item label="城市黑名单" :label-width="fromViewCofing.label_width">
            <el-cascader v-model="form.region_blocks" size="mini" placeholder="请选择地区" class="inp"
              :props="{ multiple: true, checkStrictly: true }" :options="city" clearable filterable />

            <span style="padding-left: 10px; color: #9e9e9e; font-size: 12px">黑名单具有最高优先级</span>
          </el-form-item>

          <el-form-item label="渠道条件类型" :label-width="fromViewCofing.label_width">
            <el-radio-group v-model="form.channel_restriction_type">
              <el-radio label="deny">不允许</el-radio>
              <el-radio label="allow">仅允许</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="渠道选择" :label-width="fromViewCofing.label_width">
            <el-select v-model="form.channel_ids" class="inp" multiple placeholder="请选择">
              <el-option v-for="item in channel_select" :key="item.id" :label="item.id" :value="item.id" />
            </el-select>
          </el-form-item>

          <el-form-item :label-width="fromViewCofing.label_width" prop="today_push_max"
            :rules="[{ required: true, message: '每天最大推送量不能为空' }]" label="每天最大推送量">
            <el-input v-model="form.today_push_max" size="mini" class="inp" />
          </el-form-item>

          <el-form-item :label-width="fromViewCofing.label_width"
            :rules="[{ required: true, message: '周一至周五时间区间不能为空' }]" label="周一至周五">
            <el-time-picker v-model="form.control_time.monday_to_friday.temporal_interval" class="inp"
              style="margin-right: 14px" is-range format="HH:mm" range-separator="至" start-placeholder="开始时间"
              end-placeholder="结束时间" placeholder="选择时间范围" size="mini"
              :disabled="form.control_time.monday_to_friday.status == false" />
            <el-switch v-model="form.control_time.monday_to_friday.status" />
          </el-form-item>

          <el-form-item :label-width="fromViewCofing.label_width" :rules="[{ required: true, message: '周六时间区间不能为空' }]"
            label="周六">
            <el-time-picker v-model="form.control_time.saturday.temporal_interval" class="inp"
              style="margin-right: 14px" is-range format="HH:mm" range-separator="至" start-placeholder="开始时间"
              end-placeholder="结束时间" placeholder="选择时间范围" size="mini"
              :disabled="form.control_time.saturday.status == false" />
            <el-switch v-model="form.control_time.saturday.status" />
          </el-form-item>

          <el-form-item :label-width="fromViewCofing.label_width" :rules="[{ required: true, message: '周日时间区间不能为空' }]"
            label="周日">
            <el-time-picker v-model="form.control_time.sunday.temporal_interval" class="inp" style="margin-right: 14px"
              is-range format="HH:mm" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间"
              placeholder="选择时间范围" size="mini" :disabled="form.control_time.sunday.status == false" />

            <el-switch v-model="form.control_time.sunday.status" />
          </el-form-item>

          <el-form-item label="API" :label-width="fromViewCofing.label_width" prop="apifun">
            <el-select v-model="form.apifun" class="inp" placeholder="请选择" clearable>
              <el-option v-for="item in partnerPushDowApiCalss" :key="item.value" :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="24" :xs="24" :md="12" :lg="12">
          <p class="two_title">条件 1</p>

          <el-form-item :label-width="fromViewCofing.label_width" prop="loan_amount_min"
            :rules="[{ required: true, message: '贷款金额不能为空' }]" label="最小贷款金额">
            <el-input v-model="form.loan_amount_min" class="inp" size="mini" placeholder="请输入" />
          </el-form-item>

          <el-form-item :label-width="fromViewCofing.label_width" prop="loan_amount_max"
            :rules="[{ required: true, message: '贷款金额不能为空' }]" label="最大贷款金额">
            <el-input v-model="form.loan_amount_max" class="inp" size="mini" placeholder="请输入" />
          </el-form-item>

          <el-form-item :label-width="fromViewCofing.label_width" prop="age_min"
            :rules="[{ required: true, message: '最小年龄不能为空' }]" label="最小年龄">
            <el-input v-model="form.age_min" class="inp" size="mini" placeholder="最小年龄" />
          </el-form-item>

          <el-form-item :label-width="fromViewCofing.label_width" prop="age_max"
            :rules="[{ required: true, message: '最大年龄不能为空' }]" label="最大年龄">
            <el-input v-model="form.age_max" class="inp" size="mini" placeholder="最大年龄" />
          </el-form-item>

          <el-form-item :rules="[{ required: true, message: '芝麻分不能为空' }]" label="芝麻分"
            :label-width="fromViewCofing.label_width" prop="sesame_scores">
            <el-select v-model="form.sesame_scores" class="inp" multiple placeholder="请选择">
              <el-option key="0,600" label="600以下" value="0,600" />
              <el-option key="600,649" label="600-649" value="600,649" />
              <el-option key="650,699" label="650-699" value="650,699" />
              <el-option key="700,max" label="700以上" value="700,max" />
            </el-select>
          </el-form-item>

          <el-form-item :rules="[{ required: true, message: '职业不能为空' }]" label="职业"
            :label-width="fromViewCofing.label_width" prop="works">
            <el-select v-model="form.works" class="inp" placeholder="请选择" multiple>
              <el-option key="civil_servant" label="公务员" value="civil_servant" />
              <el-option key="public_institution" label="事业单位" value="public_institution" />
              <el-option key="private_corporation" label="民营" value="private_corporation" />
              <el-option key="state_corporation" label="国企" value="state_corporation" />
            </el-select>
          </el-form-item>

          <el-form-item :rules="[{ required: true, message: '信用状况不能为空' }]" label="信用状况"
            :label-width="fromViewCofing.label_width" style="margin-bottom: 30px">
            <el-select v-model="form.credit_status" multiple class="inp" placeholder="请选择">
              <el-option key="no_overdue" label="无逾期" value="no_overdue" />
              <el-option key="current_overdue" label="当前有逾期" value="current_overdue" />
              <el-option key="overdue_cleared" label="逾期已结清" value="overdue_cleared" />
            </el-select>
          </el-form-item>

          <p class="two_title">条件 2</p>

          <el-form-item :rules="[{ required: true, message: '花呗额度不能为空' }]" label="花呗额度"
            :label-width="fromViewCofing.label_width">
            <el-select v-model="form.huabei_quotas" multiple class="inp" placeholder="请选择">
              <el-option key="no" label="无" value="no" />
              <el-option key="0,5000" label="0-5000" value="0,5000" />
              <el-option key="5000,max" label="5000以上" value="5000,max" />
            </el-select>
          </el-form-item>

          <el-form-item :rules="[{ required: true, message: '白条额度不能为空' }]" label="白条额度"
            :label-width="fromViewCofing.label_width" style="margin-bottom: 30px">
            <el-select v-model="form.baitiao_quotas" multiple class="inp" placeholder="请选择">
              <el-option key="no" label="无" value="no" />
              <el-option key="0,5000" label="0-5000" value="0,5000" />
              <el-option key="5000,max" label="5000以上" value="5000,max" />
            </el-select>
          </el-form-item>

          <el-row>
            <el-col :span="12">
              <el-form-item :rules="[{ required: true, message: '车产不能为空' }]" label="车产">
                <el-radio-group v-model="form.car" size="mini">
                  <el-radio-button label="1">有</el-radio-button>
                  <el-radio-button label="0">无</el-radio-button>
                </el-radio-group>
              </el-form-item>

              <el-form-item :rules="[{ required: true, message: '房产不能为空' }]" label="房产">
                <el-radio-group v-model="form.house" size="mini">
                  <el-radio-button label="1">有</el-radio-button>
                  <el-radio-button label="0">无</el-radio-button>
                </el-radio-group>
              </el-form-item>

              <el-form-item :rules="[{ required: true, message: '公积金不能为空' }]" label="公积金">
                <el-radio-group v-model="form.accumulation_fund" size="mini">
                  <el-radio-button label="1">有</el-radio-button>
                  <el-radio-button label="0">无</el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item :rules="[{ required: true, message: '社保不能为空' }]" label="社保">
                <el-radio-group v-model="form.social_security" size="mini">
                  <el-radio-button label="1">有</el-radio-button>
                  <el-radio-button label="0">无</el-radio-button>
                </el-radio-group>
              </el-form-item>

              <el-form-item :rules="[{ required: true, message: '保单不能为空' }]" label="保单">
                <el-radio-group v-model="form.insurance" size="mini">
                  <el-radio-button label="1">有</el-radio-button>
                  <el-radio-button label="0">无</el-radio-button>
                </el-radio-group>
              </el-form-item>

              <el-form-item :rules="[{ required: true, message: '企业主不能为空' }]" label="企业主">
                <el-radio-group v-model="form.business_owner" size="mini">
                  <el-radio-button label="1">有</el-radio-button>
                  <el-radio-button label="0">无</el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item :label-width="fromViewCofing.label_width" prop="satisfied_num"
            :rules="[{ required: true, message: '满足条件个数不能为空' }]" label="满足条件个数">
            <el-input v-model="form.satisfied_num" size="mini" class="inp" />
          </el-form-item>
        </el-col>

        <el-col :span="24" :xs="24" :md="24" :lg="24" style="margin-top: 60px">
          <el-form-item label="前置筛选">
            <el-switch v-model="form.precondition_status" :active-value="1" :inactive-value="0" />
          </el-form-item>

          <el-col v-show="form.precondition_status == 1" :span="24">
            <el-form-item label="白户/非白户" :label-width="fromViewCofing.label_two_width">
              <el-radio-group v-model="form.whitelist" size="mini">
                <el-radio label="whitelist">白户</el-radio>
                <el-radio label="not_whitelist">非白户</el-radio>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="无逾期设置" :label-width="fromViewCofing.label_two_width">
              <el-col>
                <div style="display: flex">
                  <el-checkbox v-model="form.overdue_loan_count_m0_6m_status" style="width: 140px" :true-label="1"
                    :false-label="0">近六个月M数</el-checkbox>
                  <el-input v-model="form.overdue_loan_count_m0_6m"
                    :disabled="form.overdue_loan_count_m0_6m_status == 0" class="inp" placeholder="M数" />
                </div>

                <div style="display: flex; margin-top: 10px">
                  <el-checkbox v-model="form.overdue_loan_count_m0_12m_status" style="width: 140px" :true-label="1"
                    :false-label="0">近十二个月M数</el-checkbox>
                  <el-input v-model="form.overdue_loan_count_m0_12m"
                    :disabled="form.overdue_loan_count_m0_12m_status == 0" class="inp" placeholder="M数" />
                </div>
              </el-col>
            </el-form-item>

            <el-form-item :label-width="fromViewCofing.label_two_width" label="贷款天数">
              <el-input v-model="form.credit_loan_duration" class="inp" />
            </el-form-item>

            <el-form-item :label-width="fromViewCofing.label_two_width" label="还款率">
              <el-input v-model="form.normal_repayment_ratio" class="inp">
                <template slot="append">%</template></el-input>
            </el-form-item>

            <el-form-item :label-width="fromViewCofing.label_two_width" label="结清笔数">
              <el-input v-model="form.loan_settled_orders" class="inp" />
            </el-form-item>

            <el-form-item v-if="jsAuthJudgment('manage')" :label-width="fromViewCofing.label_two_width" label="近1个月">
              <el-col>
                <div class="form_item_one">
                  <span class="fio_title">贷款笔数</span>
                  <el-input v-model="form.loan_count_1_month.min" class="fio_inp" />
                  <span class="fio_divide">至</span>
                  <el-input v-model="form.loan_count_1_month.max" disabled class="fio_inp" />
                </div>

                <div class="form_item_one">
                  <span class="fio_title">履约笔数</span>
                  <el-input v-model="form.loan_performance_count_1m.min" class="fio_inp" />
                  <span class="fio_divide">至</span>
                  <el-input v-model="form.loan_performance_count_1m.max" disabled class="fio_inp" />
                </div>

                <div class="form_item_one">
                  <span class="fio_title">贷款金额</span>
                  <el-input v-model="form.loan_amount_1_month.min" class="fio_inp" />
                  <span class="fio_divide">至</span>
                  <el-input v-model="form.loan_amount_1_month.max" disabled class="fio_inp" />
                </div>

                <div class="form_item_one">
                  <span class="fio_title">履约金额</span>
                  <el-input v-model="form.loan_performance_amount_1m.min" class="fio_inp" />
                  <span class="fio_divide">至</span>
                  <el-input v-model="form.loan_performance_amount_1m.max" disabled class="fio_inp" />
                </div>
              </el-col>
            </el-form-item>

            <el-form-item :label-width="fromViewCofing.label_two_width" label="近3个月">
              <el-col>
                <div class="form_item_one">
                  <span class="fio_title">贷款笔数</span>
                  <el-input v-model="form.loan_count_3_months.min" class="fio_inp" />
                  <span class="fio_divide">至</span>
                  <el-input v-model="form.loan_count_3_months.max" disabled class="fio_inp" />
                </div>

                <div class="form_item_one">
                  <span class="fio_title">履约笔数</span>
                  <el-input v-model="form.loan_performance_count_3m.min" class="fio_inp" />
                  <span class="fio_divide">至</span>
                  <el-input v-model="form.loan_performance_count_3m.max" disabled class="fio_inp" />
                </div>

                <div class="form_item_one">
                  <span class="fio_title">贷款金额</span>
                  <el-input v-model="form.loan_amount_3_months.min" class="fio_inp" />
                  <span class="fio_divide">至</span>
                  <el-input v-model="form.loan_amount_3_months.max" disabled class="fio_inp" />
                </div>

                <div class="form_item_one">
                  <span class="fio_title">履约金额</span>
                  <el-input v-model="form.loan_performance_amount_3m.min" class="fio_inp" />
                  <span class="fio_divide">至</span>
                  <el-input v-model="form.loan_performance_amount_3m.max" disabled class="fio_inp" />
                </div>
              </el-col>
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>

      <div class="form_footer">
        <el-button type="success" @click="fromSubmit('refForm')">提交</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
import { getConfigCurrent, getUserId } from "@/utils/appUtil";
import { apiOrganizationSelects } from "@/api/apiOrganization";
import { getToken } from "@/utils/auth";
import {
  apiAgentList,
  apiChannelConciseAll,
  apiProductCreate,
  apiProductDetails,
} from "@/api/apiCommon";
import { apiCity } from "@/api/apiConfig";
import {
  authJudgment,
  assignmentForm,
  processDetailsFormData,
  processFormData,
} from "@/utils/appUtil";

export default {
  name: "Index",
  data() {
    return {
      isManage: false, //authJudgment("manage"), // 是否是管理员
      init_form: {
        id: 0,
        business_uid: "",
        o_id: "",
        name: "",
        plan_name: "",
        cooperative_price: "",
        agency_price: "", // 代理价格，只有管理员才能查看和编辑
        real_price: "",
        weight: 0, // 权重，只有管理员才能查看和编辑
        apifun: "",
        category: "organization",
        ext_link: "",
        entry_status: 0,
        loan_type: "nationwide",
        regions: [],
        region_blocks: [],
        today_push_max: 100,
        loan_amount_max: 200000,
        loan_amount_min: 1,
        age_min: 18,
        age_max: 65,
        car: 0,
        house: 0,
        accumulation_fund: 0,
        social_security: 0,
        insurance: 0,
        business_owner: 0,
        overdue: 0,
        satisfied_num: 0,
        precondition_status: 0,
        whitelist: "whitelist",
        channel_restriction_type: "deny",
        is_exclusive: 0,
        channel_ids: [],
        overdue_loan_count_m0_6m: 0,
        overdue_loan_count_m0_6m_status: 0,
        overdue_loan_count_m0_12m: 0,
        overdue_loan_count_m0_12m_status: 0,
        credit_loan_duration: 0,
        normal_repayment_ratio: 0,
        loan_settled_orders: 0,
        loan_count_1_month: {
          min: 0,
          max: 9999999,
        },
        loan_performance_count_1m: {
          min: 0,
          max: 9999999,
        },
        loan_amount_1_month: {
          min: 0,
          max: 9999999,
        },
        loan_performance_amount_1m: {
          min: 0,
          max: 9999999,
        },
        loan_count_3_months: {
          min: 0,
          max: 9999999,
        },
        loan_performance_count_3m: {
          min: 0,
          max: 9999999,
        },
        loan_amount_3_months: {
          min: 0,
          max: 9999999,
        },
        loan_performance_amount_3m: {
          min: 0,
          max: 9999999,
        },
        credit_status: "",
        sesame_scores: "0,600",
        huabei_quotas: "no",
        baitiao_quotas: "no",
        works: "",
        today_start_time: "00:00",
        today_end_time: "23:59",
        control_time: {
          monday_to_friday: {
            temporal_interval: [
              new Date(2024, 8, 5, 9, 0),
              new Date(2024, 8, 5, 18, 0),
            ],
            status: true,
          },
          saturday: {
            temporal_interval: [
              new Date(2024, 8, 5, 9, 0),
              new Date(2024, 8, 5, 18, 0),
            ],
            status: true,
          },
          sunday: {
            temporal_interval: [
              new Date(2024, 8, 5, 9, 0),
              new Date(2024, 8, 5, 18, 0),
            ],
            status: false,
          },
        },
      },
      form: {},
      time_picker: {
        temporal_interval: [
          new Date(2024, 8, 5, 0, 0),
          new Date(2024, 8, 5, 23, 59),
        ],
      },
      uploading_img: {
        headers: {},
        api_uploading_img_url: "",
        api_uploading_video_url: "",
        dialogImageUrl: "",
        dialogImgVisible: false,
        disabled: false,
        fileList: [],
      },
      fromViewCofing: {
        input_width: "120px",
        label_width: "120px",
        label_two_width: "140px",
      },
      business_list: [],
      organization: [],
      organization_select: [],
      channel_select: [],
      city: [],
      loading: {
        dialog_create: false,
        table: false,
        form: false,
      },

      partnerPushDowApiCalss: [],
    };
  },
  created() {
    const _this = this;
    this.isManage = authJudgment("manage"); // 是否是管理员
    this.form = { ...this.init_form };
    var params = this.$route.query;
    if (params.id != 0) {
      this.reqApiProductDetails(params.id);
    } else {
    }
    if (this.jsAuthJudgment("manage")) {
      this.reqApiAgent();
    } else if (
      this.jsAuthJudgment("business") ||
      this.jsAuthJudgment("business_agency")
    ) {
      this.reqApiOrganization("");
    }
    this.reqApiCity();

    apiChannelConciseAll().then((response) => {
      const result = response.data.list;
      _this.channel_select = result;
    });

    getConfigCurrent().then((response) => {
      // console.log(response,'response')
      _this.partnerPushDowApiCalss = response.partnerPushDowApiCalss;
      // console.log(response, 'response')
      // _this.calculation_type_options = response["channel"]["type_v1"];
      // _this.blocked_org_type_options = response?.organization?.loantype || []
    });
  },
  methods: {
    // 权限判断
    jsAuthJudgment(agree_group) {
      return authJudgment(agree_group);
    },
    // 切换商务人员
    changeSelectBusinessuid(business_uid) {
      this.form.o_id = "";
      this.reqApiOrganization(business_uid);
    },
    /** 表单提交 */
    fromSubmit() {
      const _this = this;
      const formData = JSON.parse(JSON.stringify(this.form));
      // return
      this.$confirm("是否确认提交?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$refs["refForm"].validate((valid) => {
            if (valid) {

              _this.loading_start("form");
              processFormData(formData, "product").then((response) => {
                // console.log(response, "response");
                // return
                apiProductCreate(response)
                  .then((response) => {
                    // _this.loading_end("form");

                    if (response.code == 1) {

                      _this.$message({
                        message: response.msg,
                        type: "success",
                      });

                      if (_this.form.id > 0) {

                      } else {
                        _this.$router.go(-1);
                      }

                    }

                    setTimeout(function () {
                      window.location.reload();
                    }, 1000)

                    _this.loading_end("form");
                  })
                  .catch(function (result) {

                    // setTimeout(function () {
                    //   window.location.reload();
                    // }, 1000)


                    _this.loading_end("form");

                  });
              });
            } else {
              this.$message({
                message: "部分内容未填写",
                type: "warning",
              });
              _this.loading_end("form");
              return false;
            }
          });
          return;
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 获取商务人员
    reqApiAgent() {
      const _this = this;
      _this.loading_start("form");
      apiAgentList({
        page: 1,
        size: 99,
        status: "normal",
        group_id: "2,3,5",
      }).then((response) => {
        const result = response.data.datalist.data;
        _this.business_list = result;
        _this.loading_end("form");
      });
    },
    // 获取城市
    reqApiCity() {
      const _this = this;
      _this.loading_start("form");
      apiCity({}).then((response) => {
        const result = response.data;
        _this.city = result.city;
        _this.loading_end("form");
      });
    },
    // 时间选择器确认
    timePickerChange(e) {
      this.form.today_start_time = this.formatTime(e[0]);
      this.form.today_end_time = this.formatTime(e[1]);
    },
    // 获取机构列表
    reqApiOrganization(business_uid) {
      const _this = this;
      _this.loading_start("form");
      apiOrganizationSelects({
        page: 1,
        size: 99,
        business_uid: business_uid,
      }).then((response) => {
        const result = response.data;
        _this.organization_select = result.selects;
        _this.loading_end("form");
      });
    },
    // 获取详情
    reqApiProductDetails(id) {
      const _this = this;
      _this.loading_start("form");
      if (!id) {
        return;
      }
      apiProductDetails({
        id: id,
      })
        .then((response) => {
          const details = response.data.details;
          // console.log(details,'details')
          // response = assignFormParams(_this.form, details);
          _this.form = assignmentForm(_this.form, details);
          console.log(_this.form, "_this.form");
          _this.loading_end("form");
        })
        .catch(function (result) {
          _this.$message.error(result.msg);
        });
    },
    // 加载开始...
    loading_start(keys) {
      if (Array.isArray(keys)) {
        keys.forEach((key) => {
          this.loading[key] = true;
          setTimeout(() => {
            this.loading[key] = false;
          }, 5000);
        });
      } else {
        this.loading[keys] = true;
        setTimeout(() => {
          this.loading[keys] = false;
        }, 5000);
      }
    },
    // 加载结束...
    loading_end(keys) {
      if (Array.isArray(keys)) {
        keys.forEach((key) => {
          this.$nextTick(() => {
            this.loading[key] = false;
          });
        });
      } else {
        this.$nextTick(() => {
          this.loading[keys] = false;
        });
      }
    },
  },
  beforeDestroy(){
    console.log("重置isManage")
    this.isManage = false
  },
};
</script>

<style lang="scss">
// .body {
//   background-color: #fff !important;

//   .title {
//     font-size: 36px;
//   }

//   .form {
//     width: 100%;
//     height: 100%;
//     margin-bottom: 80px;

//     .two_title {
//       font-size: 18px;
//       color: #616161;
//     }

//     .inp {
//       width: 280px;
//     }

//     .textarea {
//       width: 380px;
//     }

//     .upload {
//       .tip {
//         margin-left: 10px;
//         color: #616161;
//       }
//     }

.form_item_one {
  display: flex;
  align-items: center;
  margin-bottom: 10px;

  .fio_title {
    width: 80px;
  }

  .fio_divide {
    padding: 0px 15px;
  }

  .fio_inp {
    width: 80px;
  }
}

//     .form_footer {
//       position: absolute;
//       left: 0;
//       bottom: 0;
//       width: 100%;
//       background-color: #616161;
//       padding: 10px;
//       text-align: center;
//     }
//   }
// }</style>
